//
//  CallTool.m
//  Tang
//
//  Created by lanou on 15/12/7.
//  Copyright © 2015年 352324497@qq.com. All rights reserved.
//

#import "CallTool.h"

@implementation CallTool
+ (CGFloat)heightForNSStringWithString:(NSString *)sting width:(CGFloat)width fontSize:(CGFloat)size space:(CGFloat)space
{
    if (sting == nil)
    {
        return 0;
    }
    //创建事例
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:sting];
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    
    // 设置间距
    [style setLineSpacing:space * KWidth / 414];
    
    //range 适用那一段字体
    [attStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, sting.length)];
    
    CGRect bounds = [sting boundingRectWithSize:CGSizeMake(width, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:size],NSParagraphStyleAttributeName : style} context:nil];
  
    return bounds.size.height;
}

+ (CGFloat)heightWithLabel:(UILabel *)label ForNSStringWithString:(NSString *)sting width:(CGFloat)width fontSize:(CGFloat)size space:(CGFloat)space
{
    //创建事例
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:sting];
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    
    // 设置间距
    [style setLineSpacing:space * KWidth / 414];
    
    //range 适用那一段字体
    [attStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, sting.length)];
    
    CGRect bounds = [sting boundingRectWithSize:CGSizeMake(width, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:size],NSParagraphStyleAttributeName : style} context:nil];
    //赋值label 
    label.attributedText = attStr;
    return bounds.size.height;
}

+ (CGFloat)widthForNstringWithString:(NSString *)string fontSize:(CGFloat)size
{
    CGSize aSize = [string sizeWithAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:size]}];
    return aSize.width;
}

+ (void)alertActionWithTitle:(NSString *)title message:(NSString *)message other:(NSString *)other uiViewController:(UIViewController *)vc
{
    UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
////    UIAlertAction *otherAction = [UIAlertAction actionWithTitle:other style:UIAlertActionStyleCancel handler:nil];
//    [alertVc addAction:otherAction];
    [vc presentViewController:alertVc animated:YES completion:^
    {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [alertVc dismissViewControllerAnimated:YES completion:nil];
        });
        
    }];
}


@end
